package study.ttl.service.impl;


import cn.hutool.core.date.DateUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import study.ttl.entity.Comment;
import study.ttl.mapper.CommentMapper;
import study.ttl.service.CommentService;

import java.util.List;

@Service
public class CommentServiceImpl implements CommentService {

    @Autowired
    private CommentMapper commentMapper;



    /**
     * 添加评价
     * @param comment
     */
    @Override
    public void add(Comment comment) {
        comment.setCreateTime(DateUtil.now());
        commentMapper.insert(comment);
    }

    /**
     * 根据id删除评价
     * @param id
     */
    @Override
    public void deleteById(Integer id) {
        commentMapper.deleteById(id);
    }


    /**
     * 修改评价信息
     * @param comment
     */
    @Override
    public void update(Comment comment) {
        commentMapper.updateById(comment);
    }

    /**
     * 根据id查询评价
     * @param id
     * @return
     */
    @Override
    public Comment selectById(Integer id) {
        Comment comment = commentMapper.selectById(id);
        return comment;
    }

    /**
     * 查询所有评价
     * @return
     */
    @Override
    public List<Comment> selectAll(Comment comment) {
        List<Comment> userList = commentMapper.selectAll(comment);
        return userList;
    }

    /**
     * 分页查询评价
     * @param pageNum
     * @param pageSize
     * @param comment
     * @return
     */
    @Override
    public PageInfo<Comment> selectPage(Integer pageNum, Integer pageSize, Comment comment) {
        PageHelper.startPage(pageNum, pageSize);
        List<Comment> commentList = commentMapper.selectAll(comment);
        return PageInfo.of(commentList);
    }

    /**
     * 批量删除评价
     * @param ids
     */
    @Override
    public void deleteBatch(List<Integer> ids) {
        commentMapper.deleteBatch(ids);
    }







}
